<template>
  <div class="index">
    <div class="formBox">
        <p class="item"><span class="name">触发优惠价 ：</span><input v-model="date.order_amount" class="slong" placeholder="请输入内容"></input></p>
        <p class="item"><span class="name">优惠百分比 ：</span><input v-model="date.ratio" class="slong" placeholder="请输入内容"></input></p>
        <p class="item inputBox"><button @click="submit" class="submitInput">确定</button><button @click="empty" class="emptyInput">重置</button></p>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import axios from 'axios'
import { Get, Post ,Put ,Delete,InputEmail} from '@/config/api'

export default {
  name: 'index',
  data() {
    return {
        list:[],
        date:{
          order_amount:'',
          ratio:''
        }
    }
  },
  computed:{
    //检查表单
    VueFrom(){
      if(this.Input(this.date.order_amount)&&this.Input(this.date.ratio)){
        return true
      }else{
        return false
      }
    }
  },
  methods: {
    //提交
    async submit() {
      if(this.VueFrom){
        this.$store.dispatch("loadOpen");
        let data={
            "order_amount":this.date.order_amount,
            "ratio":this.date.ratio
        }
        await Post('/order/buy/config/',this.$store.state.token,data).then(function(res){
          console.log(res)
          alert('添加成功')
        }).catch(function(err){
          alert(err.data.message)
        })
        this.$store.dispatch("loadClose");
        this.$router.push('/sallList')
      }else{
        alert('请正确填写信息')
      }
    },

    //清空
    empty() {
      for(var key in this.date){
        this.date[key]=''
      }
    }
  }
}

</script>

